package ray;

import java.awt.geom.Point2D;

import javax.vecmath.Color3f;

import object.HorizontalQuad;

import scene.IntersectionInfo;
import scene.Scene;
import util.Point3D;

public class CameraRay extends Ray {

	private Point2D pixel;
	private boolean insideObject;

	public CameraRay(Point3D start, Point3D end, Point2D pixel, boolean insideObject) {
		super(start, end);

		this.pixel = pixel;
		this.insideObject = insideObject;
	}

	@Override
	public Color3f getColor(int depth) {
		Color3f color = null;
		IntersectionInfo intersect = Scene.getInstance()
				.getClosestIntersection(this);
		if (intersect == null) {
			color = Scene.getInstance().getBackgroundColor();
		} else {
			if (intersect.getObject() instanceof HorizontalQuad) {
				color = ((HorizontalQuad) intersect.getObject())
						.getProceduralColor(intersect);
				// color = ((HorizontalQuad) intersect.getObject())
				// .getImageColor(intersect);
			} else {
				color = intersect.getObject().getIllumination(intersect, depth, insideObject);
			}
		}
		return color;
	}

	public Point2D getCorrespondingPixel() {
		return pixel;
	}

}
